<?php

/**
 * 竞拍基础
 *
 * Created by PhpStorm.
 * user: Evan
 * Date: 16/8/8
 * Time: 上午1:22
 */
class Base extends MY_Api_Controller
{
    /**
     * 竞拍列表页
     */
    public function index()
    {
        $cid   = (int)$this->input->get_post('cid');
        $uid   = $this->uid;
        $page  = (int)$this->input->get_post('page');
        $limit = (int)$this->input->get_post('limit');

        $is_public = (int)$this->input->get_post('is_public');

        $this->load->service('auction/service_auction_base');

        if(isset($is_public)){
            $data = $this->service_auction_base->index_new($cid, $page, $limit, $uid, $is_public);
        }else{
            $data = $this->service_auction_base->index($cid, $page, $limit, $uid);
        }





        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 发布拍卖
     */
    public function create()
    {
        $uid         = $this->uid;
        $cid         = (int)$this->input->get_post('cid');
        $title       = trim($this->input->get_post('title'));
        $start_time  = trim($this->input->get_post('start_time'));
        $play_time   = trim($this->input->get_post('play_time'));
        $duration    = (int)$this->input->get_post('duration');
        $time_limit  = (int)$this->input->get_post('time_limit');
        $start_price = (int)$this->input->get_post('start_price');
        $min_fare    = (int)$this->input->get_post('min_fare');
        $pic         = (int)$this->input->get_post('pic');
        $summary     = trim($this->input->get_post('summary'));
        
        $is_public     = intval($this->input->get_post('is_public'));
        //$is_charge     = intval($this->input->get_post('is_charge'));
        $amount     = intval($this->input->get_post('amount'));
        $ratio     = intval($this->input->get_post('ratio'));
        
        $start_time = $start_time?$start_time:date('Y-m-d H:i:s');
        $time_limit = floor((strtotime($play_time)-strtotime($start_time)-600)/60);

        $param = array
        (
            'uid'         => $uid,
            'cid'         => $cid,
            'title'       => $title,
            'start_time'  => $start_time,
            'play_time'   => $play_time,
            'duration'    => $duration,
            'time_limit'  => $time_limit,
            'start_price' => $start_price,
            'min_fare'    => $min_fare,
            'pic'         => $pic,
            'summary'     => $summary,
        		
        	'is_public'     => $is_public,
        	//'is_charge'     => $is_charge,
        	'amount'     => $amount,
        	'ratio'     => $ratio,
        );


        $this->load->service('auction/service_auction_base');
        $data = $this->service_auction_base->create($param);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 发布竟拍
     */
    public function publish()
    {
        $uid          = $this->uid;
        $type         = (int)$this->input->get_post('type');
        $title        = trim($this->input->get_post('title'));
        $summary      = trim($this->input->get_post('summary'));
        $pic          = $this->input->get_post('pic');
        $pic          = json_decode($pic, true);
        //$video        = $this->input->get_post('video');
        $cid          = (int)$this->input->get_post('cid');
        $play_time    = trim($this->input->get_post('play_time'));
        $duration     = (int)$this->input->get_post('duration');
        $start_price  = (int)$this->input->get_post('start_price');
        $ticket_price = (int)$this->input->get_post('ticket_price');
        $wheat_price  = (int)$this->input->get_post('wheat_price');


        $param = array
        (
            'uid'          => $uid,
            'type'         => $type,
            'title'        => $title,
            'summary'      => $summary,
            'pic'          => $pic,
            'cid'          => $cid,
            'play_time'    => $play_time,
            'duration'     => $duration,
            'start_price'  => $start_price,
            'ticket_price' => $ticket_price,
            'wheat_price'  => $wheat_price,
        );

        $this->load->service('auction/service_auction_publish');
        $data = $this->service_auction_publish->index($param);


        $this->json_output($data['data'], $data['status']);
    }
}